package com.eastfair.home.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.service.HomeViolationRecordService;
import com.eastfair.venueservice.dto.ViolationRecordDTO;
import com.eastfair.venueservice.vo.ViolationRecordVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * <p>
 * 前端控制器
 * 违规处罚记录
 * </p>
 *
 * @author lyw
 * @date 2022-08-11
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/homeViolationRecord")
@Api(value = "homeViolationRecord", tags = "违规处罚记录")
public class HomeViolationRecordController {

    @Resource
    private HomeViolationRecordService homeViolationRecordService;

    /**
     * 查询违规惩罚记录列表分页
     *
     * @param params the params
     * @return r
     */
    @ApiOperation(value = "查询违规惩罚记录列表分页")
    @PostMapping(value = "/queryViolationRecordList")
    public R<Page<ViolationRecordVO>> queryViolationRecordList(@RequestBody PageParams<ViolationRecordDTO> params) {
        log.info("queryViolationRecordList - 查询违规惩罚记录列表分页, param={}", params);
        try {
            Page<ViolationRecordVO> page = homeViolationRecordService.queryViolationRecordList(params);
            return R.success(page);
        } catch (BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 查询违规惩罚记录详情
     *
     * @param violationRecordDTO the violation record dto
     * @return r
     */
    @ApiOperation(value = "查询违规惩罚记录详情")
    @PostMapping(value = "/queryViolationRecordInfo")
    public R<ViolationRecordVO> getViolationRecord(@RequestBody ViolationRecordDTO violationRecordDTO) {
        log.info("queryViolationRecordInfo - 查询违规惩罚记录详情, param={}", violationRecordDTO);
        try {
            ViolationRecordVO violationRecordVO = homeViolationRecordService.getViolationRecord(violationRecordDTO);
            return R.success(violationRecordVO);
        } catch (BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 保存违规惩罚记录
     *
     * @param violationRecordDTO the violation record dto
     * @return r
     */
    @ApiOperation(value = "保存违规惩罚记录")
    @SysLog("添加违规记录")
    @PostMapping(value = "/saveViolationRecordInfo")
    public R<Boolean> saveViolationRecord(@RequestBody ViolationRecordDTO violationRecordDTO) {
        log.info("saveViolationRecord - 保存违规惩罚记录, violationRecordDTO={}", violationRecordDTO);
        try {
            return R.success(homeViolationRecordService.saveViolationRecord(violationRecordDTO));
        } catch (BizException biz) {
            return R.fail(biz);
        }
    }


    /**
     * 修改违规惩罚记录
     *
     * @param violationRecordDTO the violation record dto
     * @return r
     */
    @ApiOperation(value = "修改违规惩罚记录")
    @SysLog("修改违规记录")
    @PostMapping(value = "/updateViolationRecordInfo")
    public R<Boolean> updateViolationRecord(@RequestBody ViolationRecordDTO violationRecordDTO){
        log.info("updateViolationRecord - 修改违规记录, violationRecordDTO={}", violationRecordDTO);
        try {
            return R.success(homeViolationRecordService.updateViolationRecord(violationRecordDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 更新处罚扣款.
     *
     * @param violationRecordDTO the violation record dto
     * @return the r
     */
    @ApiOperation(value = "更新处罚扣款")
    @PostMapping(value = "/update/publishAmount")
    public R<Boolean> updatePublishAmount(@RequestBody ViolationRecordDTO violationRecordDTO) {
        log.info("updatePublishAmount - 更新处罚扣款, violationRecordDTO={}", violationRecordDTO);
        try {
            return R.successDef(homeViolationRecordService.updatePunishAmount(violationRecordDTO));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 撤销处罚.
     *
     * @param id the id
     * @return the r
     */
    @ApiOperation(value = "撤销处罚")
    @SysLog("撤销处罚")
    @GetMapping(value = "/update/cancel/{id}")
    public R<Boolean> updateViolationCancel(@PathVariable("id") Long id) {
        log.info("updateViolationCancel - 撤销处罚, id={}", id);
        try {
            return R.successDef(homeViolationRecordService.updateViolationCancel(id));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 删除违规惩罚记录
     *
     * @param id the id
     * @return r
     */
    @ApiOperation(value = "删除违规惩罚记录")
    @SysLog("删除违规记录")
    @GetMapping(value = "/delViolationRecordInfo/{id}")
    public R<Boolean> delViolationRecord(@PathVariable Long id){
        log.info("delViolationRecord - 删除违规惩罚记录, id={}", id);
        try {
            return R.success(homeViolationRecordService.delViolationRecord(id));
        } catch(BizException biz) {
            return R.fail(biz);
        }
    }

    /**
     * 发送配置收款商户的站内信.
     *
     * @param violationRecordDTO the violation record dto
     * @return the r
     */
    @PostMapping("/send/config/payee/innerMsg")
    public R<Boolean> sendConfigPayeeInnerMsg(@RequestBody ViolationRecordDTO violationRecordDTO) {
        log.info("sendConfigPayeeInnerMsg - 发送配置收款商户的站内信, violationRecordDTO={}", violationRecordDTO);
        try {
            return R.successDef(homeViolationRecordService.sendConfigPayeeInnerMsg(violationRecordDTO));
        } catch (BizException e) {
            return R.fail(e);
        }
    }
}